//
//  time.swift
//  DemoUI
//
//  Created by 白瑾浩 on 2022/3/4.
//
//定时器
import Foundation
class time{
    
    
    
    func time(){
        
    //        timer2 = Timer(timeInterval: (1.0 / 4000.0) , target: self, selector: #selector(drawFur2), userInfo: nil, repeats: true)
    //        RunLoop.main.add(timer2!, forMode: .common)
    //        timer2?.fire()
        var seconds = 90;
        let timerd : DispatchSourceTimer = DispatchSource.makeTimerSource(flags: [], queue: DispatchQueue.global())
        timerd.scheduleRepeating(deadline: .now(), interval: .seconds(1)/*, leeway: .milliseconds(100)*/)
        timerd.setEventHandler {
                 seconds -= 1
                if seconds <= 0 {
                    timerd.cancel()
                        DispatchQueue.main.async {
                                  /*更改UI*/
                            print( "1111" )
                          }
                }else {
                      DispatchQueue.main.async {
                       /*更改UI*/
                          print( "22222" )
                      }
           }
        }
        timerd.resume()
        timer2 = Timer.scheduledTimer(timeInterval: 1.0, target:self, selector: #selector(timerTest), userInfo: nil, repeats: true)

       
        
    }

    @objc func timerTest() {
            print("timer info - \(Date.init())")
     }
    var index = 0
    var timer2:Timer?
    func drawFur2(){
        print("=============222=")
//        if datas.count-index < 640{
//            return
//        }
//        print("==============")
//        var d = datas.subdata(in: index..<index+640)
//
//
//        mPCMDataPlayer?.play(&d, length: UInt32( d.count ) )
//
        index = index + 640
    }

    
}

